package com.atguigu.tingshu.user.rpc;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.user.service.VipServiceConfigService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description:
 *
 * @author Yanxinhao on 2025/1/18
 */
@Tag(name = "[远程调用]-用户信息接口")
@RestController
@RequestMapping("/api/user/rpc")
public class RpcUserApiController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private VipServiceConfigService vipServiceConfigService;

    /**
     * [rpc]
     * 根据用户Id获取用户信息
     * @param userId 用户id
     * @return  用户信息
     */
    @Operation(summary = "根据用户id获取用户信息")
    @GetMapping("getUserInfoVo/{userId}")
    public Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId) {
        // 获取用户信息
        UserInfoVo userInfoVo = userInfoService.getUserInfoVoByUserId(userId);
        return Result.ok(userInfoVo);
    }


    /**
     * [rpc]
     * 根据用户id和专辑id，获取用户购买过的音频数据集合
     * @param userId 用户id
     * @param albumId 专辑id
     * @return 用户购买过的音频数据集合
     */
    @GetMapping("/getUserPaidTrackList/{userId}/{albumId}")
    @Operation(summary = "根据用户id和专辑id，获取用户购买过的音频数据集合")
    public Result<List<UserPaidTrack>> getUserPaidTrackList(@PathVariable Long userId,
                                                            @PathVariable Long albumId){
        List<UserPaidTrack> result = userInfoService.getUserPaidTrackList(userId,albumId);
        return Result.ok(result);
    }


    /**
     * 根据用户id和专辑id，获取用户购买过的专辑数据集合
     * @param userId 用户id
     * @param albumId 专辑id
     * @return 用户购买过的专辑
     */
    @GetMapping("/getUserPaidAlbumList/{userId}/{albumId}")
    @Operation(summary = "根据用户id和专辑id，获取用户购买过的专辑数据集合")
    public Result<List<UserPaidAlbum>> getUserPaidAlbumList(@PathVariable(value = "userId") Long userId,
                                                     @PathVariable(value = "albumId") Long albumId){
        List<UserPaidAlbum> result = userInfoService.getUserPaidAlbumList(userId,albumId);
        return Result.ok(result);
    }


    /**
     * [rpc]
     * 根据vip套餐的id获取套餐信息
     * @param itemId 套餐id
     * @return 套餐信息
     */
    @GetMapping("/getVipConfigById/{itemId}")
    @Operation(summary = "根据vip套餐的id获取套餐信息")
    Result<VipServiceConfig> getVipConfigById(@PathVariable(value = "itemId") Long itemId){
        VipServiceConfig config = vipServiceConfigService.getVipConfigById(itemId);
        return Result.ok(config);
    }
}